<template>
  <div id="app">
    <div class="login_contain">
      <div class="login_box">
        <!-- <div class="login_logo"></div> -->
        <el-form
          ref="loginform"
          v-model="loginform"
          label-width="80px"
          class="login_form"
          status-icon
        >
          <!-- 名字 -->
          <el-form-item label="账号" prop="username" key="username">
            <el-input
              placeholder="请输入账号"
              prefix-icon="el-icon-user-solid"
              v-model="loginform.username"
            ></el-input>
          </el-form-item>
          <!-- 密码 -->
          <el-form-item label="密码" prop="password" key="password">
            <el-input
              placeholder="请输入密码"
              prefix-icon="el-icon-user"
              show-password
              v-model="loginform.password"
            ></el-input>
          </el-form-item>
          <!-- 按钮 -->
          <el-form-item class="btns">
            <el-switch
              v-model="value1"
              disabled
              inactive-text="点击开启耶耶虫的爱"
            ></el-switch>
            <el-button type="primary" @click="resetForm(loginform)"
              >重置</el-button
            >
            <el-button @click="submitForm(loginform)">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "app",
  data() {
    return {
      value1: false,
      loginform: {
        username: "",
        password: "",
      },

      rules: {
        username: [
          { required: true, message: "请输入用户名称", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入用户密码", trigger: "blur" },
        ],
      },
    };
  },

  methods: {
    // async submitForm(e) {
    //   this.$http
    //     .post("http://tp.ppwbom.com/index.php?s=/api/common/index/login", e)
    //     .then((res) => {
    //       if (res.status != 200) {
    //         this.$message.success("登陆成功");
    //          window.sessionStorage.setItem("token", res.data.token);
    //       } else {
    //         this.$message.error("登陆失败");
    //       }
    //     });
    // },
    async submitForm(e) {
      this.$http
        .post("http://127.0.0.1:8888/api/private/v1/login", e)
        .then((res) => {
          if (res.data.meta.status != 200) {
            this.$message.error("登陆失败");
          } else {
            this.$message.success("登陆成功");
            console.log('res=',res)
            window.sessionStorage.setItem("token", res.data.data.token);
            this.$router.push("/home");
          }
        });
    },
    resetForm(e) {
      e.username = "";
      e.password = "";
    },
  },
};
</script>
<style lang="less" scoped>
.login_contain {
  background-color: #d5a6bd;
  height: 100vh;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  .login_logo {
    position: absolute;
    margin-top: -35%;
    width: 150px;
    height: 150px;
    border-radius: 50%;
    background-color: #cc99ff;
    box-shadow: 0 0 10px #ddd;
  }
  .login_box {
    // position:absolute;
    display: flex;
    background-color: #ffff;
    min-width: 260px;
    width: 300px;
    padding: 40px;
    border-radius: 5px;
    margin: 0 auto;
    justify-content: center;
    align-items: center;
  }
}
.login_form {
  min-width: 260px;
  width: 300px;
}
.btns {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0px;
}
/deep/ .el-form-item__label {
  text-align: center;
  padding: 0 0 0 0;
}
</style>
